package com.hro.hro_app.database;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBManager extends SQLiteOpenHelper {

	public static final String DB_NAME = "hrorooster.db";
	public static final int DB_VERSION = 2;
	Context context;

	public DBManager(Context context) {

		super(context, DB_NAME, null, DB_VERSION);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

		Log.i("database", "Create " + DB_NAME);

		String CreateQuery;
		CreateQuery = "create table rooster (_uid text primary key, start integer, end integer, teacher text , module text, location text);";
		db.execSQL(CreateQuery);
		CreateQuery = "create table teacher (code text primary key, absent bool);";
		db.execSQL(CreateQuery);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

		db.execSQL("drop table if exists teacher");
		db.execSQL("drop table if exists rooster");
		Log.d(ApplicationInfo.class.getName(), "onUpdate dropped");
		this.onCreate(db);
	}
}